<!DOCTYPE html>
<html>
<head>
	<title><?php echo $title." | ".$desc ?></title>
	<?php $this->load->view('assets-importer'); ?>
</head>
<body>
	<?php $this->load->view('nav'); ?>
	<div id="outer">
		<div class="container">
			<?php 
			$notif = $this->session->flashdata('notif');
			$status = $this->session->flashdata('notif_status');
			?>
			<?php if($status != ""): ?>
				<?php if($status == "0"): ?>
					<div class="notif notif-gagal"><?php echo $notif ?></div>
				<?php endif; ?>
				<?php if($status == "1"): ?>
					<div class="notif notif-sukses"><?php echo $notif ?></div>
				<?php endif; ?>
			<?php endif; ?>
			
			<div id="main-content">		
				<?php if(get_cookie("c_usr_status") != "" && get_cookie("c_usr_status") != "verified"): ?>
					<div class="notif notif-gagal" style="text-align: center">
					<?php if(get_cookie("c_usr_status") == "blocked"): ?>
						This user currently blocked
					<?php elseif(get_cookie("c_usr_status") == "not verified"): ?>
						This user still not verified yet
					<?php endif; ?>
					</div>
				<?php endif; ?>

				<?php foreach($post_per_cat as $post_rec): ?>					
					<div class="post-outer">
						<?php  
						$post_id = $post_rec['jonu_post_id'];
						$post_tgl = substr($post_rec['jonu_post_date'], 8,2);
						$post_bln = substr($post_rec['jonu_post_date'], 5,2);
						$permalink = $post_bln.'/'.$post_tgl.'/'.$post_id.'/'.$post_rec['jonu_post_permalink'];						
						?>
						<h2 class="home-post-title"><a href="<?php echo site_url("post/show/$permalink") ?>"><?php echo $post_rec['jonu_post_title'] ?></a></h2>
						<img class="home-post-img" src="<?php echo base_url("asset/img/posts-image/$post_rec[jonu_post_image]") ?>" width="100%" height="auto"/>
						<div class="home-post-detail">
							<?php  
							$this->db->where('jonu_post_id', $post_rec['jonu_post_id']);
							$q_get_likes = $this->db->get('jonu_like');
							$get_likes = $q_get_likes->result_array();

							$this->db->where('jonu_post_id', $post_rec['jonu_post_id']);
							$q_get_dislikes = $this->db->get('jonu_dislike');
							$get_dislikes = $q_get_dislikes->result_array();
							?>
							<span><i class="fa fa-user fa-fw"></i> <?php echo $post_rec['jonu_user_fullname'] ?></span> 
							<span><i class="fa fa-thumbs-o-up fa-fw"></i> <?php echo count($get_likes) ?></span>
							<span><i class="fa fa-thumbs-o-down fa-fw"></i> <?php echo count($get_dislikes) ?></span>
							<span><i class="fa fa-folder-open fa-fw"></i> <?php echo $post_rec['jonu_post_view'] ?></span>
						</div>
						<div class="home-post-desc">
							<?php if(strlen($post_rec['jonu_post_content']) > 200): ?>
								<?php echo substr($post_rec['jonu_post_content'], 0, 300)." . . . ." ?>
								<a href="<?php echo site_url("post/show/$permalink") ?>"><small>Read More</small></a>
							<?php else: ?>
								<?php echo $post_rec['jonu_post_content']; ?>
							<?php endif; ?>
						</div>

						<div class="home-post-btn-container">
							<span class="pull-left">
								<?php if(get_cookie("c_usr_id") == "" || get_cookie("c_usr_usrname") == "" || get_cookie("c_usr_fullname") == ""): ?>
									<a href="#" title="Login to like" class="btn home-post-btn" style="margin-right:5px;float:none !important" disabled>
										<i class="fa fa-thumbs-up"></i>
									</a>
									<a href="#" title="Login to dislike" class="btn home-post-btn" style="margin-right:5px;float:none !important" disabled>
										<i class="fa fa-thumbs-down"></i>
									</a>
								<?php else: ?>
									<?php  
									$this->db->where('jonu_user_id', get_cookie('c_usr_id'));
									$this->db->where('jonu_post_id', $post_rec['jonu_post_id']);
									$q_like = $this->db->get('jonu_like');
									$res_like = $q_like->result_array();								
									?>
									<?php if(count($res_like) == 1): ?>
										<a href="#" title="You liked this" class="home-post-btn btn-jonu" style="margin-right:5px;"><i class="fa fa-thumbs-up"></i></a>
									<?php elseif(count($res_like) == 0): ?>
										<form class="frm-like-dislike" action="<?php echo site_url("home/like/$post_rec[jonu_post_id]") ?>" method="post">
											<button class="home-post-btn" type="submit" title="Like" name="btn_like" value="Like"><i class="fa fa-thumbs-up"></i></button>
										</form>
									<?php endif; ?>

									<?php  
									$this->db->where('jonu_user_id', get_cookie('c_usr_id'));
									$this->db->where('jonu_post_id', $post_rec['jonu_post_id']);
									$q_dislike = $this->db->get('jonu_dislike');
									$res_dislike = $q_dislike->result_array();								
									?>
									<?php if(count($res_dislike) == 1): ?>
										<a href="#" title="You disliked this" class="home-post-btn btn-jonu" style="margin-right:5px;float:none !important"><i class="fa fa-thumbs-down"></i></a>
									<?php elseif(count($res_dislike) == 0): ?>
										<form class="frm-like-dislike" action="<?php echo site_url("home/dislike/$post_rec[jonu_post_id]") ?>" method="post">
											<button class="home-post-btn" type="submit" title="Dislike" name="btn_dislike" value="Dislike"><i class="fa fa-thumbs-down"></i></button>
										</form>
									<?php endif; ?>
								<?php endif; ?>
							</span>
							<span class="pull-right">
								<a href="#" class="home-share-fb btn-share home-post-btn" title="Share to Facebook">Facebook</a>
								<a href="#" class="home-share-twitter btn-share home-post-btn" title="Share to Twitter">Twitter</a>
							</span>
						</div>
					</div>					
				<?php endforeach; ?>
				<?php if(count($post_per_cat) == 0): ?>
					<div class="alert alert-danger" style="text-align:center;"><i class="fa fa-fw fa-info-circle"></i> No post for this category</div>
				<?php endif; ?>
				<div id="home-pagination">
					<?php //echo $post['halaman'] ?>
				</div>
			</div>
			<?php $this->load->view('sidebar'); ?>
		</div>	
		<div class="container credit">
			Copyright &copy; 2015. <a href="<?php echo site_url() ?>">Jogja Nuws</a>.
		</div>	
	</div>
</div>
</body>
</html>